package com.cj.staservice.schedule;

import com.cj.staservice.service.StatisticsDailyService;
import com.cj.staservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author cj
 * @date 2023/4/21 22:04
 * @description
 */
@Component
public class ScheduleTask {
    @Autowired
    private StatisticsDailyService  statisticsDailyService;

    //@Scheduled(cron = "0/5 * * * * ?")
    //public void task1() {
    //    LocalDateTime localDateTime = LocalDateTime.now();
    //    System.out.println("*********++++++++++++*****执行了"+ localDateTime);
    //}

    //在每天凌晨12天自动把前一天的数据统计出来并添加
    @Scheduled(cron = "* * 1 * * ?")
    public void task2() {
        statisticsDailyService.registerCount(DateUtil.formatDate(DateUtil.addDays(new Date(), -1)));
    }
    //@Test
    //public void task3() {
    //    System.out.println(cn.hutool.core.date.DateUtil.yesterday());
    //}
}
